// pages/classHomePage/discuss/addPost/addPost.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  formSubmit: function (e) {
    let _this = this
    let form = e.detail.value
    console.log('form:', form);
    if (form['title'] == null || form['title'] == '' || form['content'] == null || form['content'] == '') {
      app.message('输入题目和内容不能为空', 'error')
    }
    let data = null
    let add_url = null
    if (wx.getStorageSync("people") == 'student') {
      add_url = '/api/admin/post/student/add_post'
      data = {
        'className': app.globalData.banji_info['className'],
        'content': form['content'],
        'student_account': wx.getStorageSync('account'),
        'title': form['title']
      }
    } else if (wx.getStorageSync("people") == 'teacher') {
      add_url = '/api/admin/post/teacher/add_post'
      data = {
        'className': app.globalData.banji_info['courseName'],
        'content': form['content'],
        'teacher_account': wx.getStorageSync('account'),
        'title': form['title']
      }
    }
    app.formPost(add_url, data).then(res => {
      console.log('发帖结果：', res);
      setTimeout(() => {
        wx.navigateBack()
      }, 1000)
      
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})